import logoSvg from '@/assets/logo.svg';
import { RequestConfig } from 'umi';
import { notification, Menu } from 'antd';
import Footer from './layouts/Footer';
import RightContent from './layouts/RightContent';
import ExtraMenu from './layouts/Menu/extra';
const { SubMenu } = Menu;

export const layout = () => {
  return {
    logo: logoSvg,
    fixedHeader:true,
    rightContentRender: () => <RightContent />,
    contentStyle:{marginTop:'5px'},
    disableContentMargin: true,
    footerRender: () => <Footer />,
    headerContentRender: (prods) => {
      if (prods.isMobile) {
        return;
      }
      return <ExtraMenu data={prods.menuData} mode='horizontal'></ExtraMenu>;
    },
    menuExtraRender :(prods) => {
      return <ExtraMenu data={prods.menuData} mode='inline'></ExtraMenu>;
    },
  };
};
//加入拦截器
export const request: RequestConfig = {
  errorHandler: (error) => {
    const { response } = error;
    if (!response) {
      notification.error({
        description: '您的网络发生异常,无法连接服务器',
        message: '网络异常',
      });
    }
    throw error;
  },
  //请求拦截
  requestInterceptors: [
    (url: string, options: RequestOptionsInit) => {
      const token = localStorage.getItem('token');
      const authHeader = {
        Authorization: 'Bearer ' + (token == null ? '' : token),
      };
      return {
        url: `${API_URL}${url}`,
        options: { ...options, interceptors: true, headers: authHeader },
      };
    },
  ],
  //响应拦截
  responseInterceptors: [
    async (response: Response) => {
      const res = await response.clone().json();
      return response;
    },
  ],
};
